package com.example.server.controller;

import com.example.server.entity.Bookshelf;
import com.example.server.service.BookshelfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bookshelf")
public class BookshelfController {

    @Autowired
    private BookshelfService bookshelfService;

    @GetMapping("/{iduser}")
    public List<Bookshelf> getBookshelfByUserId(@PathVariable int iduser) {
        return bookshelfService.getBookshelfByUserId(iduser);
    }

    @PostMapping
    public void addBookToBookshelf(@RequestBody Bookshelf bookshelf) {
        bookshelfService.addBookToBookshelf(bookshelf);
    }

    @DeleteMapping
    public void removeBookFromBookshelf(@RequestParam int iduser, @RequestParam int idbook) {
        bookshelfService.removeBookFromBookshelf(iduser, idbook);
    }

    @GetMapping("/check")
    public boolean isBookInBookshelf(@RequestParam int iduser, @RequestParam int idbook) {
        return bookshelfService.isBookInBookshelf(iduser, idbook);
    }
}
